package com.util.moduleManager
{
	import flash.events.EventDispatcher;
	
	/**
	 * 资源加载器
	 * @author Heineken
	 */
	public class ModuleManager extends EventDispatcher
	{
		public static var paths:Array = [];
		//public static var modules:Array = [];
		
		public static const READY:String = "ready";
		public static const PROGRESSING:String = "progressing";
		public static var basePath:String = "";
		public static var languageStr:String = "";
		/**
		 * 用这个可以安全的使用资源
		 * 而不用担心模块是否有已加载
		 * 没加载,加载后再执行
		 * @param	path
		 * @param	callBack
		 * @param	funObj
		 */
		public function excuteFunction(path:*,...rest):void
		{
			var _callBack:Function = null;
			var _funObj:Object = null;
			if(rest[0])
				_callBack = rest[0];
			if (rest[1])
				_funObj = rest[1];
			
			//if (modules.indexOf(path) != -1)//已加载资源
			//{
				//if (_callBack != null)
				//{
					//_callBack.apply(_funObj);
					//_callBack = null;
					//_funObj = null;
				//}
			//}
			//else//还未加载资源
			//{
			//new Module(path, _callBack, _funObj);
			//}
			if (rest[2])
				new ParallelModule(path, _callBack, _funObj);
			else
				new Module(path, _callBack, _funObj);
		}
		
		public function ModuleManager() 
		{
			if (instance != null)
				throw Error("there's no instance");
			instance = this;
		}
		
		private static var instance:ModuleManager = null;
		public static function getInstance():ModuleManager
		{
			if (instance == null)
				instance = new ModuleManager();
			return instance;
		}
	}
}